package com.ihome.android.market2.info;

import java.io.File;
import java.util.List;

import android.text.TextUtils;

import com.ihome.android.common.ConfigUtil;
import com.ihome.android.util.log.LogUtil;

public class DownloadAppInfo {
	private static final String								TAG						= DownloadAppInfo.class
																							.getSimpleName();
	public static final int									STATUS_NULL				= 0;
	public static final int									STATUS_DOWNLOADING		= 1;
	public static final int									STATUS_DOWNLOAD_FAIL	= 2;
	public static final int									STATUS_DOWNLOAD_STOP	= 3;
	public static final int									STATUS_DOWNLOAD_END		= 4;
	public static final int									STATUS_INSTALLED		= 5;


	public String											appName;
	public int												appId;
	/** 应用类型：0，标示正常应用；1，标示测试应用  Add at 2013-09-27*/
	public int												appType					= 0;
	public String											iconUrl;
	public int												progress				= 0;
	public int												preProgress;
	public int												status					= STATUS_NULL;
	public String											appUrl					= null;
	public String											finishTime;
	public String											saveUrl;
	public String											softSize;
	public double											rate;
	public String											version;
	public String											pkgName;
	public long												userNum;
	public boolean											needUpdate;
	public String											updateTime;
	public String											updateVersionDes;
	public double											price;
	public double											tempsize;
	public String											apkFileSize;


	public String getApkFileSize() {
		return apkFileSize;
	}

	public void setApkFileSize(String apkFileSize) {
		this.apkFileSize = apkFileSize;
	}

	/**
	 * @return the tempsize
	 */
	public double getTempsize() {
		return tempsize;
	}

	/**
	 * @param tempsize
	 *            the tempsize to set
	 */
	public void setTempsize(double tempsize) {
		this.tempsize = tempsize;
	}

	/**
	 * @return the price
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * @param price
	 *            the price to set
	 */
	public void setPrice(double price) {
		this.price = price;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateVersionDes() {
		return updateVersionDes;
	}

	public void setUpdateVersionDes(String updateVersionDes) {
		this.updateVersionDes = updateVersionDes;
	}

	public boolean isNeedUpdate() {
		return needUpdate;
	}

	public void setNeedUpdate(boolean needUpdate) {
		this.needUpdate = needUpdate;
	}

	public String getPkgName() {
		return pkgName;
	}

	public long getUserNum() {
		return userNum;
	}

	public void setUserNum(long userNum) {
		this.userNum = userNum;
	}

	public void setPkgName(String pkgName) {
		this.pkgName = pkgName;
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public int getAppId() {
		return appId;
	}

	public void setAppId(int appId) {
		this.appId = appId;
	}
	
	public int getAppType() {
		return appType;
	}

	public void setAppType(int appType) {
		this.appType = appType;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public int getProgress() {
		return progress;
	}

	public void setProgress(int progress) {
		this.progress = progress;
	}

	public int getPreProgress() {
		return preProgress;
	}

	public void setPreProgress(int preProgress) {
		this.preProgress = preProgress;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getAppUrl() {
		return appUrl;
	}

	public void setAppUrl(String appUrl) {
		this.appUrl = appUrl;
	}

	public String getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(String finishTime) {
		this.finishTime = finishTime;
	}

	public String getSaveUrl() {
		if(TextUtils.isEmpty(saveUrl)){
			File file = new File(ConfigUtil.FILE_PATH + getAppName() + ".apk");
			if(file.exists()){
				saveUrl = file.getAbsolutePath();
			}
		}
		return saveUrl;
	}

	public void setSaveUrl(String saveUrl) {
		this.saveUrl = saveUrl;
	}

	public String getSoftSize() {
		return softSize;
	}

	public void setSoftSize(String softSize) {
		this.softSize = softSize;
	}

	public static int getStatusNull() {
		return STATUS_NULL;
	}

	public static int getStatusDownloading() {
		return STATUS_DOWNLOADING;
	}

	public static int getStatusDownloadFail() {
		return STATUS_DOWNLOAD_FAIL;
	}

	public static int getStatusDownloadStop() {
		return STATUS_DOWNLOAD_STOP;
	}

	public static int getStatusDownloadEnd() {
		return STATUS_DOWNLOAD_END;
	}

	public static int getStatusInstalled() {
		return STATUS_INSTALLED;
	}
	
	/**
	 * @return the rate
	 */
	public double getRate() {
		return rate;
	}

	/**
	 * @param rate
	 *            the rate to set
	 */
	public void setRate(double rate) {
		this.rate = rate;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}


	public boolean containsApp(List<DownloadAppInfo> mList) {
		boolean flag = false;

		if (mList == null || mList.size() == 0) {
			LogUtil.e(TAG, "containsApp List<DownloadAppInfo> Is NULL");
			return false;
		}
		for (int i = 0, len = mList.size(); i < len; i++) {
			DownloadAppInfo temp = mList.get(i);
			if (temp.getAppId() == getAppId()) {
				LogUtil.v(TAG, "mList Contains Current App, AppId Is + " + getAppId());
				flag = true;
				return flag;
			}
		}

		return flag;
	}
	
	public boolean containsAppByPkgName(List<DownloadAppInfo> mList) {
		boolean flag = false;

		if (mList == null || mList.size() == 0) {
			LogUtil.e(TAG, "containsAppByPkgName List<DownloadAppInfo> Is NULL");
			return false;
		}
		for (int i = 0, len = mList.size(); i < len; i++) {
			DownloadAppInfo temp = mList.get(i);
			if (temp.getPkgName().equals(getPkgName())) {
				LogUtil.v(TAG, "mList Contains Current App, PkgName Is + " + getPkgName());
				flag = true;
				return flag;
			}
		}

		return flag;
	}
	
}
